﻿#ifndef Base_Context_h__
#define Base_Context_h__
#include <memory>
#include <functional>

#define _DEBUG
#include "Log.h"

class Base_MessageQueue;
struct Base_Message;

class Base_Context
{
public:
	typedef std::function<void(Base_Message *)> ContextCallback;

	static Base_Context * new_base_context()
	{
		auto b=new Base_Context();
		LOG("创建一个contxt  handle :%d\n", b->m_handle);
		return b;
	}

	void register_process(const ContextCallback& callback)
	{
		this->callback = callback;
	}

	uint32_t get_handle() { return m_handle; }
	const std::shared_ptr<Base_MessageQueue>&  get_mq() { return m_mq; }


	ContextCallback callback;
private:
	Base_Context();
	~Base_Context() {};
	Base_Context(const Base_Context&) = delete;
	Base_Context & operator=(const Base_Context &) = delete;

private:
	std::shared_ptr<Base_MessageQueue> m_mq;
	uint32_t m_handle;

	static uint32_t next_handle;   //下一个可用的 handle;
};

#endif // Base_Context_h__
